<?php

/**
 * qikDropShipper Extension
 *
 * @category   FavoredMinds
 * @package    Vendor
 * @author     FavoredMinds Solution (geedubya15@gmail.com)
 * @copyright  Copyright (c) 2010 FavoredMinds.com (http://www.favoredminds.com)
 */
class PLUTUS_Home_IndexController extends Mage_Core_Controller_Front_Action {
    
    public function exportPdfAction(){
        // We'll be outputting a PDF
        $sku = $this->getRequest()->getParam("sku");
        if(!empty($sku)){
            $filePath = Mage::getBaseDir("media")."/productpdf/$sku".".pdf";
            
            if(file_exists($filePath)){
                header('Content-type: application/pdf');
                header("Content-Disposition: attachment; filename=$sku.pdf");
                readfile($filePath);
             
            }
        }
        else{
            $this->_redirect();
        }
    }
    public function exportPdfCatalogAction(){
        // We'll be outputting a PDF
        $category_id = $this->getRequest()->getParam("category_id");
        
        if(!empty($category_id)){
            $model = Mage::getModel("catalog/category")->load($category_id);
            if(!empty($model)){
                
                $pdfname = $model->getPdfName();
                $filePath = Mage::getBaseDir("media")."/catalog/pdf/$pdfname".".pdf";
                if(file_exists($filePath)){
                    $time = time();
                    header('Content-type: application/pdf');
                    header("Content-Disposition: attachment; filename=$time.pdf");
                    readfile($filePath);

                }
            }
        }
        
        else{
            $this->_redirect();
        }
    }
    public function downloadSpecialAction(){
        // We'll be outputting a PDF
        $file = Mage::getStoreConfig('home/general/fileoffer');
        if(!empty($file)){
            $filePath = Mage::getBaseDir("media")."/home/".$file;
            if(file_exists($filePath)){
                header('Content-type: application/pdf');
                header("Content-Disposition: attachment; filename=offer.pdf");
                readfile($filePath);
            }
        }
        else{
            $this->_redirect();
        }
    }
    public function catalogAction(){
        
        $this->loadLayout();
        $this->renderLayout();

    }
    public function searchAction(){
        
        if($this->getRequest()->getParam("oem")){
            $item = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToFilter("oem_number",$this->getRequest()->getParam("oem"))
                ->addAttributeToFilter("status",1)
                ->addAttributeToFilter("visibility",4)
                ->getFirstItem();    
        }
        elseif($this->getRequest()->getParam("sku")){
            $item = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToFilter("sku",$this->getRequest()->getParam("sku"))
                ->addAttributeToFilter("status",1)
                ->addAttributeToFilter("visibility",4)
                ->getFirstItem();    
        }
        elseif($this->getRequest()->getParam("model")){
            
            $item = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToFilter("model_number",$this->getRequest()->getParam("model"))
                ->addAttributeToFilter("status",array("eq",1))
                ->addAttributeToFilter("visibility",array("eq",4))
                ->getFirstItem();    
            
        }
        $data = $item->getData();
        
        if(!empty($data)){
            
           $productUrl = $item->getProductUrl();
           $this->_redirectUrl($productUrl);
           return;
        }
        $this->loadLayout();
        $this->renderLayout();
    }
    
    
    public function specialAction(){
        $this->loadLayout();
        $this->renderLayout();
    }
}